package com.android.corestat.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import android.content.Context;

public class SingleThreadExecutor {

	private static SingleThreadExecutor mInstance;
	private static ExecutorService threadExecutor;

	private SingleThreadExecutor() {
		if (mInstance == null) {
			threadExecutor = Executors.newSingleThreadExecutor();
		}
	}

	public static SingleThreadExecutor getInstance() {
		if (mInstance == null) {
			mInstance = new SingleThreadExecutor();
		}
		return mInstance;
	}

	public void startSendThread(Context ctx) {
		WorkingThread sendTask = new WorkingThread(ctx,WorkingThread.SEND_TASK);
		threadExecutor.submit(sendTask);
	}

	public void startWriteThread(Context ctx,int seq) {
		WorkingThread writeTask = new WorkingThread(ctx,seq);
		threadExecutor.submit(writeTask);
	}
}
